<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<?php
    if(isset($_REQUEST['btnAuthorSearch']))
    {
        $searchTextFirstName = $_REQUEST['txtFirstName'];
        $searchTextLastName = $_REQUEST['txtLastName'];
        
        require 'lib/util.php';
        
        $sql = "SELECT ID, CONCAT(FirstName, IF(MiddleName IS NOT NULL, CONCAT(' ' , MiddleName , ' '), ' '), LastName) AS AuthorName FROM ref_AUTHORS WHERE FirstName LIKE '".$searchTextFirstName."%' AND LastName LIKE '".$searchTextLastName."%'";
        $rs = executeSqlQuery($sql);
        $rowCount = mysql_num_rows($rs);
    }
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <title></title>
    </head>
    <body>
        <?php
            session_start();
            include("/common/headerPage.php")
        ?>
        <div>
            <div id="menu_wrapper"></div>
            <div id="content_wrapper">
                <div id="fh_regular">Search Author</div>
                <form method="post" action="refSearchAuthors.php">
                    <table>
                        <tr>
                            <td class="text_reg">First Name: <input type="text" class="text_reg" name="txtFirstName"></td>
                            <td class="text_reg">Last Name: <input type="text" class="text_reg" name="txtLastName"></td>
                            <td><input type="submit" name="btnAuthorSearch" class="text_reg" value="Search"></td>
                            <td class="text_reg" id="fh_link_text"><a href="refAddAuthors.php">New Author</a></td>
                        </tr>
                    </table>
                </form>
                
                <?php
                    if((isset($_REQUEST['btnAuthorSearch']) && $rowCount > 0))
                    {
                        $printRowNumber = 1;
                ?>
                
        <table width="100%">
            <tr>
                <td class="text_reg">#</td>
                <td class="text_reg">Author Name</td>
                <td class="text_reg"></td>
            </tr>
            <?php
                while ($row = mysql_fetch_array($rs))
                {
            ?>
                    <tr>
                        <td class="text_reg"><?php echo $printRowNumber ?></td>
                        <td class="text_reg"><?php echo $row['AuthorName'] ?></td>
                        <td class="text_reg"><a href="refEditAuthors.php?id=<?php echo $row['ID'] ?>"><img src="images/edit_icon.png" title="Edit Author" height="16px" width="16px"></a>  <img src="images/delete_icon.png" title="Delete Author" height="16px" width="16px"></td>
                    </tr>
            <?php
                    $printRowNumber++;
                }
            ?>
        </table>
                <?php
                    }
                ?>
            </div>
        </div>
    </body>
</html>
